package com.uenpay.im.ui.old.activity.movement;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

public class PraiseMovementInvokeItem extends BaseHttpInvokeItem {
	public class PraiseMovementInvokeItemResult extends HttpInvokeResult {
	}

	public PraiseMovementInvokeItemResult getOutput() {
		return (PraiseMovementInvokeItemResult) GetResultObject();
	}

	/**
	 * 
	 * @param movementId
	 * @param pop 0:cancel 1:praise
	 */
	public PraiseMovementInvokeItem(int movementId, int pop) {
		// http://api.aitiapp.com/Activity/praise?activityid=&op=
		String url = APIConfiguration.getBaseUrl()
				+ "Activity/Activity/praise?activityid=" + movementId + "&op=" + pop
				+ "&" + APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		PraiseMovementInvokeItemResult result = new PraiseMovementInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
		return result;
	}
}
